package com.bzyd.mp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bzyd.mp.enums.SyncType;
import com.bzyd.mp.mapper.DataSyncTimeMapper;
import com.bzyd.mp.model.po.DataSyncTimePO;
import com.bzyd.mp.service.DataSyncTimeService;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.Map;

/**
 * @Description DataSyncTime表
 * @Author dangxianyue
 * @Date 2023/3/18 9:54
 */
@Service
public class DataSyncTimeServiceImpl extends ServiceImpl<DataSyncTimeMapper, DataSyncTimePO> implements DataSyncTimeService {

    @Override
    public LocalDateTime getLastSyncTime(SyncType syncType) {
        LambdaQueryWrapper<DataSyncTimePO> wrapper = new QueryWrapper<DataSyncTimePO>()
                .select("MAX(SYNC_TIME)")
                .lambda()
                .eq(DataSyncTimePO::getSyncType, syncType);
        LocalDateTime obj = this.getObj(wrapper, o -> ((Timestamp) o).toLocalDateTime());
        System.out.println("isNull: " + (obj == null));
        return obj;
    }
}
